using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Options_EventTypesAdd : System.Web.UI.Page
{

    DataSet ds = new DataSet();
    private string userID;

    protected void Page_Load(object sender, EventArgs e)
    {
            userID = Session["UserID"].ToString();

            ds = workLayerWeb.FillEventTypes(userID);

            dgvEventTypes.DataSource = ds;
            dgvEventTypes.DataBind();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (i < dgvEventTypes.Rows.Count)
                {
                    dgvEventTypes.Rows[i].ID = ds.Tables[0].Rows[i].ItemArray[ds.Tables[0].Columns.Count - 1].ToString();
                }
            }
        
    }

    private void BringEventTypes(DataSet ds)
    {
        userID = Session["UserID"].ToString();

        ds = workLayerWeb.FillEventTypes(userID);

        dgvEventTypes.DataSource = ds;
        dgvEventTypes.DataBind();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("GeneralCalendar.aspx");
    }
    protected void dgvEventTypes_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string eventTypesID = dgvEventTypes.Rows[e.RowIndex].ID;

        if (workLayerWeb.DeleteEventType(eventTypesID, Session["UserID"].ToString()))
        {
            this.Page_Load(sender, e);
        }
    }
    protected void btnAddEventTypes_Click(object sender, EventArgs e)
    {
        bool doesExist = false;
        string tempEvent = txtEventType.Text.Trim();
        //ds = workLayerWeb.FillEventTypes(Session["UserID"].ToString());

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (tempEvent == ds.Tables[0].Rows[i].ItemArray[0].ToString())
            {
                doesExist = true;
                break;
            }
        }
        if (doesExist == false)
        {
            ds = workLayerWeb.AddEventType(tempEvent, userID);
            BringEventTypes(ds);
        }
    }
}
